package com.yan;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

/**
 * TODO
 *
 * @Author: 汪焰
 * @Date: 2021/7/4 20:00
 */
public class ConsumerInfo {

    private static String infoLevel = QueueConstants.LogLevel.INFO.getLevel();

    public static void main(String[] args) throws Exception {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setUri("amqp://root:root@1.116.195.238:5672/%2f");

        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();

        channel.exchangeDeclare(QueueConstants.exchangeName, BuiltinExchangeType.DIRECT, false, false, null);

        channel.queueDeclare(QueueConstants.queueName + infoLevel, false, false, false, null);

        channel.queueBind(QueueConstants.queueName + infoLevel, QueueConstants.exchangeName, infoLevel);

        channel.basicConsume(QueueConstants.queueName + infoLevel, (consumerTag, message) -> {
            System.out.println("ConsumerInfo 收到的消息：" + new String(message.getBody()));
        }, consumerTag -> {
        });

    }
}
